package com.gm.service.user;

import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import com.gm.common.Pager;
import com.gm.dao.customer.ICustomerDao;
import com.gm.model.po.Customer;
import com.gm.tools.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2017/6/25.
 */

@Service
public class CustomerService {

    @Autowired
    private ICustomerDao customerDao;


    public PageList<Customer> getCustomerList(Pager pager){
        PageBounds pageBounds = new PageBounds(pager.getCurrentPage(), pager.getPageSize());
        return customerDao.getCustomerList(pageBounds);
    }

    public int addCustomer(Customer customer){
        customer.setStatus(1);
        customer.setCreateTime(DateUtils.getCurrentUnixTime());
        customer.setUpdateTime(DateUtils.getCurrentUnixTime());
        return customerDao.insert(customer);
    }

    public int updateCustomer(Customer customerParam){
        Customer  customer = customerDao.selectByPrimaryKey(customerParam.getId());
        customer.setName(customerParam.getName());
        customer.setRid(customerParam.getRid());
        customer.setRemark(customerParam.getRemark());
//        customer.setCode(customerParam.getCode());
//        customer.setIdCard(customerParam.getIdCard());
        customer.setAddr(customerParam.getAddr());
        customer.setUpdateTime(DateUtils.getCurrentUnixTime());
        customer.setSex(customerParam.getSex());
        return customerDao.updateByPrimaryKey(customer);
    }

    public int deleteCustomer(Integer id){
        Customer  customer = customerDao.selectByPrimaryKey(id);
        customer.setStatus(0);
        return customerDao.updateByPrimaryKey(customer);
    }

    public Customer selectByPrimaryKey(Integer id){
        return customerDao.selectByPrimaryKey(id);
    }

    public List<Customer> selectByCode(String code){
        return customerDao.selectByCode(code);
    }

    public List<Customer> selectByIdCard(String idCard){
        return customerDao.selectByIdCard(idCard);
    }

}
